js.input_class = {}


js.input_class.list = function(can){
	var me = this;
	this.group 		= '';
	this.tablecans 	= {};
	this.onPageAfter	= function(){}
	this.onPageBefore	= function(){}
	
	var ocan = window['listparams_'+can.rand+''];
	if(ocan)for(var i in ocan)this[i] = ocan[i];
	
	js.baseclass.call(this, can); 
	
	this.onPage = function(){
		this.onPageBefore();
		var tablecans = {
			url:'?m=input&a=datalist&num='+this.num+'&group='+this.group+'',
			urledit:'?m=input&a=savecell&num='+this.num+'&group='+this.group+'',
			fanye:true,checked:false,celleditor:true,caozuo:false,autoheight:true,resizeh:22,height:300,
			view:'table_view'+this.rand+'',
			columns:[{
				text:'字段',dataIndex:'fields'
			},{
				text:'内容',dataIndex:'cont'
			}],
			onloadbefore:function(d){
				if(d.fieldsarr)me.showcolumns(d.fieldsarr);
			},
			onbeforeload:function(){
				me.onbeforeload();
			},
			onitemclick:function(d){
				me.onitemclick(d);
			},
			onitemdblclick:function(d){
				me.onitemdblclick(d);
			}
		}
		if(ismobile==1)tablecans.showtype = 1;
		for(var i in this.tablecans)tablecans[i] = this.tablecans[i];
		this.table = new js.table.create(tablecans);
		this.onPageAfter();
		var input = get('fields_keyword'+this.rand+'');
		if(input)$(input).keyup(function(e){
			if(e.keyCode==13)me.search();
		});
	}
	
	this.showcolumns = function(da){
		var ds=[],d,f,i,len=da.length,fid,df=[],type,sio,j;
		for(i=0;i<len;i++){
			f= da[i];fid = f.fields;type = f.fieldstype;
			if(f.islb==1){
				d = {text:f.name,dataIndex:fid,align:f.align}
				if(f.ispx==1)d.sortable = true;
				if(f.width)d.width = f.width;
				if(f.zdsm)d.textmsg = f.zdsm;
				if(type=='checkbox')d.type = type;
				if(type=='uploadimg')d.renderer = function(v){
					if(v)return '<img src="'+v+'" onclick="js.viewimg(this)" height="24" />';
				}
				if(f.iseditlx==1)d.editor = true;
				sio = this.setColumnsinfo[fid];
				if(sio)for(j in sio)d[j]=sio[j];
				ds.push(d);
			}
			if(f.isss==1){
				df.push({name:f.name,value:fid});
			}
		}
		for(i in this.addColumnsinfo)ds.push(this.addColumnsinfo[i]);
		this.table.setColumns(ds);
		var ov = get('fields_select'+this.rand+'');
		ov.length = 1;
		js.setselectdata(ov, df, 'value');
	}

	this.setColumnsinfo = {};
	this.addColumnsinfo = [];
	this.setColumns = function(fid, val){
		this.setColumnsinfo[fid] = val;
	}
	
	this.addColumns = function(val){
		this.addColumnsinfo.push(val);
	}
	
	this.search = function(){
		var fid = get('fields_select'+this.rand+'').value;
		this.table.setparams({
			'fields_select': fid, 
			'fields_like'  : get('fields_like'+this.rand+'').value,
			'fields_keyword':jm.base64encode(get('fields_keyword'+this.rand+'').value)
		}, true);
	}
	
	this.del = function(){
		var sid = '';
		if(this.table.checked)sid = this.table.getchecked();
		if(!sid)sid = this.table.changeid;
		if(!sid){js.msg('msg','没有选中行');return;};
		var aid = sid.split(',');
		js.confirm('确定要删除选中的'+aid.length+'条记录吗？', function(jg){
			if(jg=='yes')me.dels(sid);
		});
	}
	
	this.dels = function(sid){
		js.ajax.get({
			url:'?m=input&a=delete&num='+this.num+'&group='+this.group+'&ids='+sid+'',
			loading:'删除中...',
			loadsuccess:'删除成功',
		}, function(ret){
			me.reload();
		})
	}
	
	this.reload = function(){
		this.table.reload();
	}
	
	
	this.add = function(){
		table = this.table;
		js.openinput(this.num);
	}
	
	this.edit = function(){
		if(!this.table.changeid){js.msg('msg','没有选中行');return;};
		table = this.table;
		js.openinput(this.num, this.table.changeid);
	}
	
	this.onitemclick = function(d){
		get('editbtn_'+this.rand+'').disabled = false;
		get('delbtn_'+this.rand+'').disabled = false;
	}
	
	this.onbeforeload = function(){
		get('editbtn_'+this.rand+'').disabled = true;
		get('delbtn_'+this.rand+'').disabled = true;
	}
	
	this.onitemdblclick = function(d){
		js.openxiang(this.num, d.id);
	}
	
	this.query = function(act,da){
		var url = 'index.php?m=input&a=query&act='+act+'&num='+this.num+'&group='+this.group+'';
		js.ajax.get({
			url:url,data:da,
			loading:'处理中...',
			loadsuccess:'处理完成'
		}, function(){
			me.reload();
		});
	}
}